home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.023.FracApp 2.0 / URectStack.inc1.p < prev    next >
Encoding:
Text File  |  1990-04-30  |  3.6 KB  |  111 lines  |  [TEXT/MPS ]

  1. {[j=20/53/1$] Pasmat Options}
  2.  
  3. {-------------------------------------------------------------------------------------------}
  4. {----------------------------------TRectStack Methods---------------------------------------}
  5. {-------------------------------------------------------------------------------------------}
  6. {$S AOpen}
  7.  
  8. PROCEDURE TRectStack.IRectStack(initialNumberOfRects: Integer);
  9.  
  10. { Calls IDynamicArray with “initialNumberOfRects” and an element size of SizeOf(Rect). This
  11.   will allocate enough memory in the heap to store at least an “initialNumberOfRects” of
  12.   Rects without taking any Memory Manager hit.}
  13.  
  14.     BEGIN
  15.         SELF.IDynamicArray(initialNumberOfRects, SizeOf(Rect));
  16.     END;
  17.  
  18. {-------------------------------------------------------------------------------------------}
  19. {$S ARes}
  20.  
  21. PROCEDURE TRectStack.ClearStack;
  22.  
  23. { Removes all the items from the stack. }
  24.  
  25.     BEGIN
  26.         SELF.DeleteElementsAt(1, GetSize);
  27.     END;
  28.  
  29. {-------------------------------------------------------------------------------------------}
  30. {$S ARes}
  31.  
  32. PROCEDURE TRectStack.EachRect(PROCEDURE DoToRect(theRect: Rect); direction: Boolean);
  33.  
  34. { Calls the passed DoToRect procedure for each item on the stack. It traverses the stack in
  35.   ‘direction’ order. If ‘direction’ is kForward, then we start with the first element pushed
  36.   onto the stack, and proceed to the last (most recent) element on the stack. }
  37.  
  38.     VAR
  39.         dummy:                ArrayIndex;
  40.  
  41.     FUNCTION DoToItem(elementIndex: ArrayIndex): Boolean;
  42.  
  43.         VAR
  44.             theRect:            Rect;
  45.  
  46.         BEGIN
  47.  
  48.         { Get the rectangle that is associated with this index number, and pass it off
  49.           to the procedure that was passed in to us: DoTorect. }
  50.  
  51.             SELF.GetElementsAt(elementIndex, @theRect, 1);
  52.             DoToRect(theRect);
  53.  
  54.         { The core iterating routine of TDynamicArray - EachElementDoTil - is designed
  55.           to iterate until a certain condition is true. This condition is defined by
  56.           the PROCEDURE parameter that is passed to it. EachElementDoTil just keeps
  57.           iterating until that procedure returns TRUE (or until we run out of
  58.           elements). Since we want EachRect to iterate over ALL items on the stack, we
  59.           always return FALSE. }
  60.  
  61.             DoToItem := FALSE;
  62.         END;
  63.  
  64.     BEGIN
  65.  
  66.     { We iterate over the stack by calling the generic EachElementDoTil method of
  67.       TDynamicArray. For each element in the stack, our DoToItem procedure will be
  68.       called with the index of the item that needs to be processed. Our DoToItem
  69.       procedure uses this index to get the corresponding Rect, which it in turns
  70.       passes to the DoToRect procedure that was passed to us. }
  71.  
  72.         dummy := SELF.EachElementDoTil(DoToItem, direction);
  73.     END;
  74.  
  75. {-------------------------------------------------------------------------------------------}
  76. {$S ARes}
  77.  
  78. PROCEDURE TRectStack.PushRect(theRect: Rect);
  79.  
  80. { Takes the Rect you pass it, and pushes it on the stack. It does this by inserting the item
  81.   after the last item in the array. We know how large the array is with the
  82.   TDynamicArray.GetSize method. }
  83.  
  84.     BEGIN
  85.         SELF.InsertElementsBefore(GetSize + 1, @theRect, 1);
  86.     END;
  87.  
  88. {-------------------------------------------------------------------------------------------}
  89. {$S ARes}
  90.  
  91. PROCEDURE TRectStack.PopRect(VAR theRect: Rect);
  92.  
  93. { Returns the first Rect on the stack. That Rect is then removed from the stack. }
  94.  
  95.     BEGIN
  96.         SELF.GetElementsAt(GetSize, @theRect, 1);
  97.         SELF.DeleteElementsAt(GetSize, 1);
  98.     END;
  99.  
  100. {-------------------------------------------------------------------------------------------}
  101. {$S AFields}
  102.  
  103. PROCEDURE TRectStack.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  104.                                                 fieldType: Integer)); OVERRIDE;
  105.  
  106.     BEGIN
  107.         DoToField('TRectStack', NIL, bClass);
  108.  
  109.         INHERITED Fields(DoToField);
  110.     END;
  111.